﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Security;
using System.Diagnostics;
using System.Collections.Observable.DebugViews;

namespace System.Collections.Observable
{
    [DebuggerTypeProxy(typeof(ObservableDictionaryDebugView<,>))]
    [DebuggerDisplay("Count = {Count}")]
    [Serializable]
    public class ObservableDictionary<TKey,TValue>: ObservableDictionaryBase<TKey,TValue, Dictionary<TKey,TValue> >
    {
        
        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that is empty, has the default initial capacity, and uses the default
        //     equality comparer for the key type.
        public ObservableDictionary() :
            base(new Dictionary<TKey, TValue>())
        {
        }

        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that contains elements copied from the specified System.Collections.Generic.IDictionary<TKey,TValue>
        //     and uses the default equality comparer for the key type.
        //
        // Parameters:
        //   dictionary:
        //     The System.Collections.Generic.IDictionary<TKey,TValue> whose elements are
        //     copied to the new ObservableDictionary<TKey,TValue>.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     dictionary is null.
        //
        //   System.ArgumentException:
        //     dictionary contains one or more duplicate keys.
        public ObservableDictionary(IDictionary<TKey, TValue> dictionary) :
            base(new Dictionary<TKey, TValue>(dictionary))
        {
        }

        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that is empty, has the default initial capacity, and uses the specified
        //     System.Collections.Generic.IEqualityComparer<T>.
        //
        // Parameters:
        //   comparer:
        //     The System.Collections.Generic.IEqualityComparer<T> implementation to use
        //     when comparing keys, or null to use the default System.Collections.Generic.EqualityComparer<T>
        //     for the type of the key.
        public ObservableDictionary(IEqualityComparer<TKey> comparer) :
            base(new Dictionary<TKey, TValue>(comparer))
        {
        }

        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that is empty, has the specified initial capacity, and uses the default
        //     equality comparer for the key type.
        //
        // Parameters:
        //   capacity:
        //     The initial number of elements that the ObservableDictionary<TKey,TValue>
        //     can contain.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     capacity is less than 0.
        public ObservableDictionary(int capacity):
            base(new Dictionary<TKey,TValue>(capacity))
        {
        }

        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that contains elements copied from the specified System.Collections.Generic.IDictionary<TKey,TValue>
        //     and uses the specified System.Collections.Generic.IEqualityComparer<T>.
        //
        // Parameters:
        //   dictionary:
        //     The System.Collections.Generic.IDictionary<TKey,TValue> whose elements are
        //     copied to the new ObservableDictionary<TKey,TValue>.
        //
        //   comparer:
        //     The System.Collections.Generic.IEqualityComparer<T> implementation to use
        //     when comparing keys, or null to use the default System.Collections.Generic.EqualityComparer<T>
        //     for the type of the key.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     dictionary is null.
        //
        //   System.ArgumentException:
        //     dictionary contains one or more duplicate keys.
        public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer):
            base(new Dictionary<TKey,TValue>(dictionary, comparer))
        {
        }

        // Summary:
        //     Initializes a new instance of the ObservableDictionary<TKey,TValue>
        //     class that is empty, has the specified initial capacity, and uses the specified
        //     System.Collections.Generic.IEqualityComparer<T>.
        //
        // Parameters:
        //   capacity:
        //     The initial number of elements that the ObservableDictionary<TKey,TValue>
        //     can contain.
        //
        //   comparer:
        //     The System.Collections.Generic.IEqualityComparer<T> implementation to use
        //     when comparing keys, or null to use the default System.Collections.Generic.EqualityComparer<T>
        //     for the type of the key.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     capacity is less than 0.
        public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer):
            base(new Dictionary<TKey,TValue>(capacity, comparer))
        {
        }

        // Summary:
        //     Gets the System.Collections.Generic.IEqualityComparer<T> that is used to
        //     determine equality of keys for the dictionary.
        //
        // Returns:
        //     The System.Collections.Generic.IEqualityComparer<T> generic interface implementation
        //     that is used to determine equality of keys for the current ObservableDictionary<TKey,TValue>
        //     and to provide hash values for the keys.
        public IEqualityComparer<TKey> Comparer 
        {
            get
            {
                return InternalCollection.Comparer;
            }
        }
        
        // Summary:
        //     Gets a collection containing the keys in the ObservableDictionary<TKey,TValue>.
        //
        // Returns:
        //     A ObservableDictionary<TKey,TValue>.KeyCollection containing
        //     the keys in the ObservableDictionary<TKey,TValue>.
        public new Dictionary<TKey, TValue>.KeyCollection Keys 
        {
            get
            {
                return InternalCollection.Keys;
            }
        }

        // Summary:
        //     Gets a collection containing the values in the ObservableDictionary<TKey,TValue>.
        //
        // Returns:
        //     A ObservableDictionary<TKey,TValue>.ValueCollection containing
        //     the values in the ObservableDictionary<TKey,TValue>.
        public new Dictionary<TKey, TValue>.ValueCollection Values 
        {
            get
            {
                return InternalCollection.Values;
            }
        }

        // Summary:
        //     Determines whether the ObservableDictionary<TKey,TValue>
        //     contains a specific value.
        //
        // Parameters:
        //   value:
        //     The value to locate in the ObservableDictionary<TKey,TValue>.
        //     The value can be null for reference types.
        //
        // Returns:
        //     true if the ObservableDictionary<TKey,TValue> contains an
        //     element with the specified value; otherwise, false.
        public bool ContainsValue(TValue value)
        {
            return InternalCollection.ContainsValue(value);
        }

        // Summary:
        //     Returns an enumerator that iterates through the ObservableDictionary<TKey,TValue>.
        //
        // Returns:
        //     A ObservableDictionary<TKey,TValue>.Enumerator structure
        //     for the ObservableDictionary<TKey,TValue>.
        public new Dictionary<TKey, TValue>.Enumerator GetEnumerator()
        {
            return InternalCollection.GetEnumerator();
        }
    }
}
